﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tycho.PerformanceTests
{
    class MethodCalls : IMethodCalls
    {
        [BenchMark, Ignore]
        private static void InterfaceCalls () {
            IMethodCalls m = new MethodCalls ();

            for (int n = 0; n < 1000000; n++) {
                m.InterfaceAdd (1, 2);
            }
        }

        [BenchMark, Ignore]
        private static void DirectCalls () {
            var m = new MethodCalls ();

            for (int n = 0; n < 1000000; n++) {
                m.DirectAdd (1, 2);
            }
        }

        [BenchMark, Ignore]
        private static void StaticCalls () {
            for (int n = 0; n < 1000000; n++) {
                StaticAdd (1, 2);
            }
        }

        [BenchMark, Ignore]
        private static void VirtualCalls () {
            var m = new MethodCalls ();

            for (int n = 0; n < 1000000; n++) {
                m.VirtualAdd (1, 2);
            }
        }

        public int InterfaceAdd (int a, int b) {
            return a + b;
        }

        public int DirectAdd (int a, int b) {
            return a + b;
        }

        public virtual int VirtualAdd (int a, int b) {
            return a + b;
        }

        public static int StaticAdd (int a, int b) {
            return a + b;
        }
    }

    internal interface IMethodCalls {
        int InterfaceAdd (int a, int b);
    }
}
